/*
  BoardIO.h, Version 1.0 beta
  July 2010, by Uwe Gartmann
*/

#ifndef BoardIO_h
#define BoardIO_h

/// Definitions
#define SLIDE_SWITCH_PIN 40
#define PUSHBUTTON_PIN 41
#define A_LED_PIN 37	// GREEN
#define LED_GREEN 37
#define B_LED_PIN 36	// YELLOW
#define LED_YELLOW 36
#define C_LED_PIN 35	// RED
#define LED_RED 35
#define RELAY_PIN 47
#define DEBUG_PINA 64	// PORTL, bit6
#define DEBUG_PINB 128	// PORTL, bit7

#define SLIDE_SW_MONITORING 0	// Switch towards Servo ports
#define SLIDE_SW_FLIGHT 1		// Switch towards GPS port

// EEPROM
#define EEPROM_MAX_ADDR		4096

// Radio setup values
#define EE_TRIM 0x00
#define EE_MIN 0x10
#define EE_MAX 0x20
#define EE_ELEVON1_TRIM 0x30
#define EE_ELEVON2_TRIM 0x32

// user gains
#define EE_XTRACK_GAIN 0x34
#define EE_XTRACK_ANGLE 0x36
#define EE_ALT_MIX 0x3B
#define EE_HEAD_MAX 0x38
#define EE_PITCH_MAX 0x39
#define EE_PITCH_MIN 0x3A
#define EE_KP 0x40
#define EE_KI 0x60
#define EE_KD 0x80
#define EE_IMAX 0xA0
#define EE_KFF 0xC0
#define EE_AN_OFFSET 0xE0

//mission specific
#define EE_CONFIG 0X0F8
#define EE_WP_MODE 0x0F9
#define EE_YAW_MODE 0x0FA	// not used
#define EE_WP_TOTAL 0x0FB
#define EE_WP_INDEX 0x0FC
#define EE_WP_RADIUS 0x0FD
#define EE_LOITER_RADIUS 0x0FE
#define EE_ALT_HOLD_HOME 0x0FF

// user configs
#define EE_AIRSPEED_CRUISE 0x103
#define EE_AIRSPEED_RATIO 0x104
#define EE_AIRSPEED_FBW_MIN 0x108
#define EE_AIRSPEED_FBW_MAX 0x109
#define EE_THROTTLE_MIN 0x10A
#define EE_THROTTLE_CRUISE 0x10B
#define EE_THROTTLE_MAX 0x10C
#define EE_THROTTLE_FAILSAFE 0x10D
#define EE_THROTTLE_FS_VALUE 0x10E
#define EE_THROTTLE_FAILSAFE_ACTION 0x110
#define EE_FLIGHT_MODE_CHANNEL 0x112
#define EE_AUTO_TRIM 0x113
#define EE_LOG_BITMASK 0x114
#define EE_REVERSE_SWITCH 0x120
#define EE_FLIGHT_MODES 0x121

// sensors
#define EE_ABS_PRESS_GND 0x116
#define EE_GND_TEMP 0x11A
#define EE_GND_ALT 0x11C
#define EE_AP_OFFSET 0x11E

// log
#define EE_LAST_LOG_PAGE 0xE00
#define EE_LAST_LOG_NUM 0xE02
#define EE_LOG_1_START 0xE04

/// Includes
#include <inttypes.h>

class BoardIO {
public:
	BoardIO();
	void Init();
	void DebugPin(uint8_t p, uint8_t m);	// p = DEBUG_PINA/DEBUG_PINB, m = ON/OFF/TOGGLE
	void LED(uint8_t l, uint8_t m);			// l = LED, m = ON/OFF/TOGGLE
	void Relay(uint8_t m);
	uint8_t SlideSwitchMode(void);
};

#endif
